/**
 * 前端和后端共用的代码
 * <p>
 * version:1.0.8 date:2015-04-30
 */
function formatFreezeType(freezeType) {
	var str = "";
	if (freezeType == 10004) {
		str = "提现冻结";
	} else if (freezeType == 10008) {
		str = "	投标预冻结";
	} else {
		str = freezeType;
	}
	return str;
}

function formatRechargeStatus(value) {
	var strStatus = "";
	if (value == 1) {
		strStatus = "失败";
	} else if (value == 2) {
		strStatus = "无效";
	} else if (value == 11) {
		strStatus = "充值中";
	} else if (value == 12) {
		strStatus = "待确认";
	} else if (value == 21) {
		strStatus = "充值成功";
	}
	return strStatus;
}

function formatTransCode(transCode, subTransCode) {
	var str = "";
	if (transCode == 3012) {
		str = "收费";
	} else if (transCode = 3011 && subTransCode == 301101) {
		str = "投标";
	} else if (transCode = 3011 && subTransCode == 301102) {
		str = "投标回款";
	} else if (transCode = 3011 && subTransCode == 301103) {
		str = "债权转让";
	} else if (transCode = 3011) {
		str = "转账";
	} else if (transCode == 4003) {
		str = "充值";
	} else if (transCode == 5002) {
		str = "提现";
	} else {
		str = transCode;
	}
	return str;
}

function formatWithdrawStatus(value) {
	var strStatus = "";
	if (value == 1) {
		strStatus = "失败";
	} else if (value == 2) {
		strStatus = "无效";
	} else if (value == 11) {
		strStatus = "等待处理";
	} else if (value == 21) {
		strStatus = "提现处理中";
	} else if (value == 31) {
		strStatus = "提现成功";
	}
	return strStatus;
}

// 格式化Transfer债权转让的状态
function formatTransferStatus(status) {
	var str = "";
	if (status == 1) {
		str = "转让失败";
	} else if (status == 2) {
		str = "已取消";
	} else if (status == 3) {
		str = "已过期";
	} else if (status == 4) {
		str = "自动取消";
	} else if (status == 11) {
		str = "转让中";
	} else if (status == 12) {
		str = "待审核";
	} else if (status == 21) {
		str = "转让成功";
	}
	return str;
}

// 格式化Money类型
function formatMoney(money) {
	if (money != null) {
		return money * 1.0 / 100;
	}
	return money;
}

function formatLoanStatus(status) {
	var str = "";
	if (status == 1) {
		str = "草稿";
	} else if (status == 2) {
		str = "无效";
	} else if (status == 3) {
		str = "审核失败";
	} else if (status == 11) {
		str = "待审核";
	} else if (status == 12) {
		str = "待发布";
	} else if (status == 21) {
		str = "招标中";
	} else if (status == 31) {
		str = "已流标";
	} else if (status == 32) {
		str = "满标待审";
	} else if (status == 41) {
		str = "还款中";
	} else if (status == 51) {
		str = "还款成功";
	}
	return str;
}

function formatChannel(channel) {
	var str = "";
	if (channel == 10) {
		str = "关于我们";
	} else if (channel == 20) {
		str = "公司动态";
	} else if (channel == 30) {
		str = "平台公告";
	} else if (channel == 40) {
		str = "帮助中心";
	} else if (channel == 200) {
		str = "其它";
	}
	return str;
}

function formatPostStatus(status) {
	var str = "";
	if (status == 0) {
		str = "正常";
	} else if (status == 2) {
		str = "草稿";
	} else {
		str = "非法"
	}
	return str;
}
function formatLoanCommentStatus(status) {
	var str = "";
	if (status == 0) {
		str = "显示";
	} else if (status == 1) {
		str = "已删除";
	}
	return str;
}

function formatPhotoStatus(status) {
	var str = "";
	if (status == 0) {
		str = "正常";
	} else if (status == 1) {
		str = "已删除";
	} else {
		str = "非法"
	}
	return str;
}

function formatPhotoType(type) {
	var str = "";
	if (type == 1) {
		str = "借款人资料";
	} else if (type == 2) {
		str = "用户身份证";
	} else if (type == 3) {
		str = "标";
	} else if (type == 4) {
		str = "首页轮播图";
	}
	return str;
}

function formatBankCardStatus(value) {
	var strStatus = "";
	if (value == 1) {
		strStatus = "无效";
	} else if (value == 11) {
		strStatus = "待审核";
	} else if (value == 21) {
		strStatus = "审核通过";
	}
	return strStatus;
}

function formatDirection(value) {
	var direction;
	if (value == "produce") {
		direction = '产生';
	} else {
		direction = '消耗';
	}
	return direction;
}

function formatType(value) {
	var type;
	if (value == "TENDER_SUCCESE") {
		type = "成功投标";
	} else if (value == "WITHDRAW_FEE") {
		type = "提现手续费";
	} else if (value == "ARTIFICIALITY_PRO") {
		type = "人工增加积分";
	} else if (value == "ARTIFICIALITY_CON") {
		type = "人工修改积分";
	} else {
		type = "不明";
	}
	return type;
}

function formatLoanApplyStatus(status) {
	var str = "";
	if (status == 0) {
		str = "未处理";
	} else if (status == 1) {
		str = "已处理";
	}
	return str;
}

function formatTenderReturnType(type) {
	var str = "";
	if (type == 0) {
		str = "正常还款";
	} else if (type == 1) {
		str = "逾期还款";
	} else if (type == 2) {
		str = "提前还款";
	} else if (type == 3) {
		str = "债权转让回款";
	}
	return str;
}

function formatRepayMethod(repayMethod){
	var str="";
	if(repayMethod=="m"){
		str ="按月分期";
	}else if(repayMethod=="e"){
		str="到期还本息";
	}else if(repayMethod=="i"){
		str="按月付息，到期还本";
	}
	return str;
}

function selectOne(id, value) {
	$("#" + id).val(value);
}

function disableOne(id) {
	$("#" + id).attr("disabled", "disabled");
}
function post(url, params, fn) {
	$.post(url, params, function(data) {
        if(data.code==-1){
        	alert("会话已超时,请重新登录.");
        	window.location= $("#loginUrl").val();
        	return;
        }
        if(data.code==-5){
        	alert("服务器繁忙,请稍后再试.");
        	return;
        }
        if(data.code ==0){
        	alert("出了点小问题:"+data.msg);
        	return;
        }
        if(data.code == -2){
        	alert("权限不足,请联系网站管理员.");
        	return;
        }
        fn(data);
	});
}
function getJSON(url, params, fn) {
	$.getJSON(url, params, function(data) {
        if(data.code==-1){
        	alert("会话已超时,请重新登录.");
        	window.location= $("#loginUrl").val();
        	return;
        }
        if(data.code==-5){
        	alert("服务器繁忙,请稍后再试.");
        	return;
        }
        if(data.code ==0){
        	alert("出了点小问题:"+data.msg);
        	return;
        }
        if(data.code == -2){
        	alert("权限不足,请联系网站管理员.");
        	return;
        }
        fn(data);
	});
}


$(function(){
	//验证
	$(".validationEngine").each(function() {
		$(this).validationEngine('attach', {
			promptPosition : 'centerRight',
			scroll : false
		});
	});
});
